//
//  HomeTopView.swift
//  我的微博
//
//  Created by shmily on 15/8/2.
//  Copyright © 2015年 Stanford-IOS8-Swift-shmilyAshen. All rights reserved.
//

import UIKit

/// 视图间的间距
let homeTopViewMargin: CGFloat = 8

/// 顶部视图
class HomeTopView: UIView {
    
    //数据模型
    var status: BlogContent? {
        didSet {
            imgIcon.sd_setImageWithURL((status?.user?.imageUrl)!)
            lblName.text = status?.user?.name
            //TODO:是否需要更改时间
//            lblTime.text = status?.created_at
//            lblSource.text = status?.source
            lblTime.text = "刚刚"
            lblSource.text = "微博 weibo.com"
            imgVip.image = status?.user?.rankImg
            imgVerified.image = status?.user?.verifiedImg
            //print(status)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        //添加界面视图
        setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //更新 UI
    private func setUpUI() {
        addSubview(imgIcon)
        addSubview(lblName)
        addSubview(lblTime)
        addSubview(lblSource)
        addSubview(imgVip)
        addSubview(imgVerified)
        
        //更新布局
       imgIcon.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: 35, height: 35),offset: CGPoint(x: homeTopViewMargin, y: homeTopViewMargin))
        lblName.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: imgIcon, size: nil, offset: CGPoint(x: homeTopViewMargin, y: 0))
        lblTime.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: imgIcon, size: nil, offset: CGPoint(x: homeTopViewMargin, y: 0))
        lblSource.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: lblTime, size: nil, offset: CGPoint(x: homeTopViewMargin, y: 0))
        imgVip.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: lblName, size: CGSize(width: 15, height: 15), offset: CGPoint(x: homeTopViewMargin, y: 0))
        imgVerified.ff_AlignVertical(type: ff_AlignType.BottomRight, referView: imgIcon, size: CGSize(width: 15, height: 15), offset: CGPoint(x: homeTopViewMargin, y: -homeTopViewMargin))
    }
    
    //懒加载视图
    //图标视图
    private lazy var imgIcon: UIImageView = UIImageView()
    //昵称视图
    private lazy var lblName: UILabel = UILabel(fontSize: 14, foreColor: UIColor.orangeColor())
    //时间视图
    private lazy var lblTime: UILabel = UILabel(fontSize: 13, foreColor: UIColor.lightGrayColor())
    //来源视图
    private lazy var lblSource: UILabel = UILabel(fontSize: 13, foreColor: UIColor.lightGrayColor())
    //vip等级视图
    private lazy var imgVip: UIImageView = UIImageView()
    //认证用户视图
    private lazy var imgVerified: UIImageView = UIImageView()
}
